/**********************************************************************
* Filename: Instant.java
* Created: 2013/05/29
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.airNova.businessLayer;

import java.util.Set;
import java.util.HashSet;
import org.quasar.airNova.persistenceLayer.Database;

public class Instant
{
	
	/***********************************************************
	* @return all instances of class Instant
	***********************************************************/
	public static Set<Instant> allInstances()
	{
		return Database.allInstances(Instant.class);
	}
	
	private int hours;
	private int minutes;
	private int seconds;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Instant()
	{
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param hours the hours to initialize
	* @param minutes the minutes to initialize
	* @param seconds the seconds to initialize
	**********************************************************************/
	public Instant(int hours, int minutes, int seconds)
	{
		this.hours = hours;
		this.minutes = minutes;
		this.seconds = seconds;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the hours of the instant
	**********************************************************************/
	public int hours()
	{
		return hours;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param hours the hours to set
	**********************************************************************/
	public void setHours(int hours)
	{
		this.hours = hours;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the minutes of the instant
	**********************************************************************/
	public int minutes()
	{
		return minutes;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param minutes the minutes to set
	**********************************************************************/
	public void setMinutes(int minutes)
	{
		this.minutes = minutes;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the seconds of the instant
	**********************************************************************/
	public int seconds()
	{
		return seconds;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param seconds the seconds to set
	**********************************************************************/
	public void setSeconds(int seconds)
	{
		this.seconds = seconds;
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	* @param t the t to set
	**********************************************************************/
	public boolean isAfter(Instant t){
		//	return if (self.hours = t.hours) then if (self.minutes = t.minutes) then (self.seconds > t.seconds) else (self.minutes > t.minutes) endif else (self.hours > t.hours) endif
		
		if(t.hours() > hours())
			return false;
		if(t.hours() == hours() && t.minutes() > minutes())
			return false;
		if(t.hours() == hours() && t.minutes() == minutes() && t.seconds() > seconds())
			return false;
		
		return true;
	}
	
	public boolean isBefore(Instant t){
		//	return if (self.hours = t.hours) then if (self.minutes = t.minutes) then (self.seconds > t.seconds) else (self.minutes > t.minutes) endif else (self.hours > t.hours) endif
		
		if(t.hours() < hours())
			return false;
		if(t.hours() == hours() && t.minutes() < minutes())
			return false;
		if(t.hours() == hours() && t.minutes() == minutes() && t.seconds() < seconds())
			return false;
		
		return true;
	}
	
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Instant [hours=" + hours + ", minutes=" + minutes + ", seconds=" + seconds + "]";
	}
	
	//	-------------------------------------------------------------------------------
	//	INVARIANTS (TODO)
	/*
	inv instantUnico
		Instant.allInstances->forAll(i1 : Instant, i2 : Instant | ((i1 <> i2) implies (((((((((i1.hours <> i2.hours) and (i1.minutes <> i2.minutes)) and (i1.seconds <> i2.seconds)) or (((i1.hours = i2.hours) and (i1.minutes <> i2.minutes)) and (i1.seconds <> i2.seconds))) or (((i1.hours <> i2.hours) and (i1.minutes = i2.minutes)) and (i1.seconds <> i2.seconds))) or (((i1.hours <> i2.hours) and (i1.minutes <> i2.minutes)) and (i1.seconds = i2.seconds))) or (((i1.hours = i2.hours) and (i1.minutes <> i2.minutes)) and (i1.seconds = i2.seconds))) or (((i1.hours = i2.hours) and (i1.minutes = i2.minutes)) and (i1.seconds <> i2.seconds))) or (((i1.hours <> i2.hours) and (i1.minutes = i2.minutes)) and (i1.seconds = i2.seconds)))))
	
	*/
}
